﻿Imports System.Configuration

Namespace Configuration

    Public Class RecipientElement
        Inherits ConfigurationElement

        '<Recipient Name="" Email="" IsActive="true" />

        <ConfigurationProperty("Name", IsKey:=True, IsRequired:=True)> _
        Public Property Name() As String
            Get
                Return DirectCast(Me("Name"), String)
            End Get
            Set(ByVal value As String)
                Me("Name") = value
            End Set
        End Property

        <ConfigurationProperty("Email", IsRequired:=True)> _
        Public Property Email() As String
            Get
                Return DirectCast(Me("Email"), String)
            End Get
            Set(ByVal value As String)
                Me("Email") = value
            End Set
        End Property

        <ConfigurationProperty("IsActive", DefaultValue:="true", IsRequired:=False)> _
        Public Property IsActive() As Boolean
            Get
                Return DirectCast(Me("IsActive"), Boolean)
            End Get
            Set(ByVal value As Boolean)
                Me("IsActive") = value
            End Set
        End Property

    End Class

    <ConfigurationCollection(GetType(RecipientElement))> _
    Public Class RecipientCollection
        Inherits ConfigurationElementCollection

        Protected Overloads Overrides Function CreateNewElement() As ConfigurationElement
            Return New RecipientElement()
        End Function

        Protected Overloads Overrides Function GetElementKey(ByVal element As ConfigurationElement) As Object
            Return DirectCast((element), RecipientElement).Name
        End Function

        Default Public Shadows ReadOnly Property Item(ByVal idx As Integer) As RecipientElement
            Get
                Return DirectCast(BaseGet(idx), RecipientElement)
            End Get
        End Property

    End Class

End Namespace
